package com.kuiandjie.web;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kuiandjie.entity.Employee;
import com.kuiandjie.entity.FileType;
import com.kuiandjie.entity.Project;
import com.kuiandjie.service.FileTypeService;
import com.kuiandjie.util.DateUtil;

public class AddFolderServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession();
		Employee emp = (Employee) session.getAttribute("employee");
		Project pro = (Project) session.getAttribute("curp");
		
		String name = request.getParameter("foldername");
		if(name == null || name == ""){
			request.getRequestDispatcher("WEB-INF/views/addfolder.jsp").forward(request, response);
		}else{
			if("POST".equals(request.getMethod())){
				
				FileTypeService fts = new FileTypeService();
				FileType ft = new FileType();
				
				ft.setCreateTime(DateUtil.getNow());
				ft.setEmployeeId(emp.getId());
				ft.setEmpName(emp.getName());
				ft.setName(name);
				ft.setProjectId(pro.getId());
				
				fts.addFloder(ft);
				
				response.sendRedirect("file.jspx");
			}else{
				response.sendError(405);
			}
		}
	}

}
